<?php
class My_Service_Kpi{
    public function revenueindex($conn, $service, $memcache, $myMem, $helperTime, $gameId, $urlModule, $urlController, $urlAction, $dateStart, $dateEnd, $arrIndex, $configGame, $configApplication, $index = null, $realtime = null){
        $data = array();
        #prepare data when time loop
        $configApplication['date']['value']     = $dateStart;
        $configApplication['dateEnd']['value']  = $dateEnd;
        foreach($arrIndex as $key => $value){
            $configApplication['index']                 = $value;
            $configApplication['channelingAgentId']     = $key;
            if(isset($index) && $index){
                $keyMem = 'mc_'.BASE_URL.'_'.ENV.'_'.$gameId.'_'.$urlController.'_'.$urlAction.'_'.$dateStart.'_'.$dateEnd.'_'.$configApplication['index'].'_'.$configApplication['channelingAgentId'].'_'.$index;
            }else{
                $keyMem = 'mc_'.BASE_URL.'_'.ENV.'_'.$gameId.'_'.$urlController.'_'.$urlAction.'_'.$dateStart.'_'.$dateEnd.'_'.$configApplication['index'].'_'.$configApplication['channelingAgentId'];
            }
            if(APPLICATION_ENV == 'local'){
                $memcache->delete($keyMem);
            }
            if(!isset($realtime) && $memcache->get($keyMem) && in_array($urlModule.'/'.$urlController,$configGame->cache->controller->toArray())){
                $data[$key] = $myMem->get($keyMem, $configGame->cache->time, $memcache);
            }else{
                $params[$key]     = $conn->{$configApplication['prepareParams2']}($configApplication);
                if(APPLICATION_ENV == 'local'){
                    echo '<pre>',print_r($params[$key]),'</pre><br />';
                }
                try{
                    $data[$key] = $service->{$configApplication['function']}($params[$key]);
                    if(APPLICATION_ENV == 'local'){
                        echo '<pre>',print_r($data[$key]),'</pre><br />';
                    }
                    if(!isset($data[$key]['status']) || (isset($data[$key]['status']) && $data[$key]['status'] != 1)){
                        $result = array(
                                        'error' => $data[$key]['status']
                                    );
                        $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params[$key],'result'=>$data[$key]),$gameId);
                        return $result;
                    }
                    if($this->checkCreatCache($dateEnd) && !isset($realtime)){
                        $myMem->set($keyMem, serialize($data[$key]), false, $configGame->cache->time, $memcache);
                    }
                }catch(Exception $ex){
                    $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params[$key],'mess'=>$ex->getMessage()),$gameId);
                }
            }
        }
        $temp = array();
        for($dateStart;$dateStart<=$dateEnd;$dateStart = $helperTime->addDate($dateStart,1)){
            foreach($arrIndex as $key => $value){
                if(isset($data[$key]['status']) && $data[$key]['status'] == 1){
                    if(isset($data[$key]['result'][$dateStart]) && is_numeric($data[$key]['result'][$dateStart])){
                        $temp[$dateStart][$key]['status'] = 1;
                        $temp[$dateStart][$key]['result'] = $data[$key]['result'][$dateStart];
                    }else{
                        $temp[$dateStart][$key]['status'] = 1;
                        $temp[$dateStart][$key]['result'] = 0;
                    }
                }
            }
        }
        $data = $temp;
        $result = array(
                        'keyMem'    => $keyMem,
                        'data'      => $data,
                    );
        return $result;
    }
    public function revenueserver($conn, $service, $memcache, $myMem, $helperTime, $gameId, $clusterId, $urlModule, $urlController, $urlAction, $dateStart, $dateEnd, $arrTitle, $configGame, $configApplication, $export = null, $index = null, $realtime = null){
        $data = array();
        #prepare data when time loop
        $configApplication['date']['value']     = $dateStart;
        $configApplication['dateEnd']['value']  = $dateEnd;
        if(isset($arrTitle) && is_array($arrTitle) && $arrTitle){
            $configApplication['serverList']        = implode(',',array_keys($arrTitle));
        }
        if($index){
            $keyMem = 'mc_'.BASE_URL.'_'.ENV.'_'.$gameId.'_'.$urlController.'_'.$urlAction.'_'.$dateStart.'_'.$dateEnd.'_'.$configApplication['index'].'_'.$configApplication['channelingAgentId'].'_'.$configApplication['serverList'].'_'.$index;
        }else{
            $keyMem = 'mc_'.BASE_URL.'_'.ENV.'_'.$gameId.'_'.$urlController.'_'.$urlAction.'_'.$dateStart.'_'.$dateEnd.'_'.$configApplication['index'].'_'.$configApplication['channelingAgentId'].'_'.$configApplication['serverList'].'_';
        }
        if(APPLICATION_ENV == 'local'){
            $memcache->delete($keyMem);
        }
        if($memcache->get($keyMem) && in_array($urlModule.'/'.$urlController,$configGame->cache->controller->toArray())){
            $data = $myMem->get($keyMem, $configGame->cache->time, $memcache);
        }else{
            $params     = $conn->{$configApplication['prepareParams2']}($configApplication);
            if(APPLICATION_ENV == 'local'){
                echo '<pre>',print_r($params),'</pre><br />';
            }
            try{
                $data = $service->{$configApplication['function']}($params);
                if(APPLICATION_ENV == 'local'){
                    echo '<pre>',print_r($data),'</pre><br />';
                }
                if(!isset($data['status']) || (isset($data['status']) && $data['status'] != 1)){
                    $result = array(
                                    'error' => $data['status']
                                );
                    $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params,'result'=>$data),$gameId);
                    return $result;
                }
                if($this->checkCreatCache($dateEnd) && !isset($realtime)){
                    $myMem->set($keyMem, serialize($data), false, $configGame->cache->time, $memcache);
                }
            }catch(Exception $ex){
                $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params,'mess'=>$ex->getMessage()),$gameId);
            }
        }
        $temp = array();
        # lấy data server theo từng channel
        if(isset($configGame->applications->channelPermission) && $configGame->applications->channelPermission == 1
        && isset($configApplication['permission']) && $configApplication['permission'] == 1){
            for($dateStart;$dateStart<=$dateEnd;$dateStart = $helperTime->addDate($dateStart,1)){
                if(isset($data['result'][$dateStart]) 
                && is_array($data['result'][$dateStart])){
                    $temp[$dateStart] = array();
                    foreach($arrTitle as $key=>$title){
                        if(!isset($temp[$dateStart][$key])){
                            $temp[$dateStart][$key] = 0;
                        }
                        foreach($data['result'][$dateStart] as $value){
                            if(isset($value['server_id']) && $value['server_id'] == $key){
                                $temp[$dateStart][$key] += $value['value'];
                            }else{
                                $temp[$dateStart][$key] += 0;
                            }
                        }
                    }
                }
            }
        }
        for($dateStart;$dateStart<=$dateEnd;$dateStart = $helperTime->addDate($dateStart,1)){
            if(isset($data['status']) && $data['status'] == 1){
                foreach($arrTitle as $key=>$title){
                    if(isset($data['result'][$dateStart]) && is_array($data['result'][$dateStart]) && isset($data['result'][$dateStart][$key])){
                        $temp[$dateStart][$key] = $data['result'][$dateStart][$key];
                    }else{
                        $temp[$dateStart][$key] = 0;
                    }
                }
            }
        }
        if($temp)
            $data = $temp;
        $result = array(
                        'keyMem'    => $keyMem,
                        'data'      => $data,
                    );
        return $result;
    }
    public function revenuegame($conn, $service, $memcache, $myMem, $helperTime, $gameId, $clusterId, $urlModule, $urlController, $urlAction, $dateStart, $dateEnd, $arrTitle, $configGame, $configApplication, $type = 'revenue', $export = null){
        $data = array();
        #prepare data when time loop
        $configApplication['date']['value']     = $dateStart;
        $configApplication['dateEnd']['value']  = $dateEnd;
        
        foreach($arrTitle as $key=>$value){
            if(isset($configGame->$type->game->$key->index)){
                $configApplication['index'] = $configGame->$type->game->$key->index;
                $keyMem = 'mc_'.BASE_URL.'_'.ENV.'_'.$gameId.'_'.$urlController.'_'.$urlAction.'_'.$dateStart.'_'.$dateEnd.'_'.$configApplication['index'];
                if(APPLICATION_ENV == 'local'){
                    $memcache->delete($keyMem);
                }
                if($memcache->get($keyMem) && in_array($urlModule.'/'.$urlController,$configGame->cache->controller->toArray())){
                    $data[$key] = $myMem->get($keyMem, $configGame->cache->time, $memcache);
                }else{
                    $params                     = $conn->{$configApplication['prepareParams2']}($configApplication);
                    if(APPLICATION_ENV == 'local'){
                        echo '<pre>',print_r($params),'</pre><br />';
                    }
                    try{
                        $data[$key] = $service->{$configApplication['function']}($params);
                        if(APPLICATION_ENV == 'local'){
                            echo '<pre>',print_r($data[$key]),'</pre><br />';
                        }
                        if(!isset($data[$key]['status']) || (isset($data[$key]['status']) && $data[$key]['status'] != 1)){
                            $result = array(
                                            'error' => $data[$key]['status']
                                        );
                            $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params,'result'=>$data[$key]),$gameId);
                            return $result;
                        }
                        if($this->checkCreatCache($dateEnd)){
                            $myMem->set($keyMem, serialize($data[$key]), false, $configGame->cache->time, $memcache);
                        }
                    }catch(Exception $ex){
                        $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params[$key],'mess'=>$ex->getMessage()),$gameId);
                    }
                }
            }
        }
        $temp = array();
        for($dateStart;$dateStart<=$dateEnd;$dateStart = $helperTime->addDate($dateStart,1)){
            foreach($arrTitle as $key=>$title){
                if(isset($data[$key]['status']) && $data[$key]['status'] == 1){
                    if(isset($data[$key]['result'][$dateStart])){
                        $temp[$dateStart][$key] = $data[$key]['result'][$dateStart];
                    }else{
                        $temp[$dateStart][$key] = 0;
                    }
                }
            }
        }
        $data = $temp;
        $result = array(
                        'keyMem'    => $keyMem,
                        'data'      => $data,
                    );
        return $result;
    }
    # pcu, acu theo channel
    public function ccuChannel($conn, $service, $memcache, $myMem, $helperTime, $gameId, $urlModule, $urlController, $urlAction, $dateStart, $dateEnd, $arrIndex, $configGame, $configApplication){
        $data = array();
        #prepare data when time loop
        $configApplication['date']['value']     = $dateStart;
        $configApplication['dateEnd']['value']  = $dateEnd;
        foreach($arrIndex as $key => $value){
            $configApplication['index']                 = $value;
            $configApplication['channelingAgentId']     = $key;
            if(isset($value['channel'])){
                $configApplication['channelingAgentId']     = $value['channel'];
            }
            if(isset($value['index'])){
                $configApplication['index']     = $value['index'];
            }
            if(isset($value['serverList'])){
                $configApplication['serverList']     = $value['serverList'];
            }
            $keyMem = 'mc_'.BASE_URL.'_'.ENV.'_'.$gameId.'_'.$urlController.'_'.$urlAction.'_'.$dateStart.'_'.$dateEnd.'_'.$configApplication['index'].'_'.$configApplication['channelingAgentId'];
            if(APPLICATION_ENV == 'local'){
                $memcache->delete($keyMem);
            }
            if(!isset($realtime) && $memcache->get($keyMem) && in_array($urlModule.'/'.$urlController,$configGame->cache->controller->toArray())){
                $data[$key] = $myMem->get($keyMem, $configGame->cache->time, $memcache);
            }else{
                $params[$key]     = $conn->{$configApplication['prepareParams2']}($configApplication);
                if(APPLICATION_ENV == 'local'){
                    echo '<pre>',print_r($params[$key]),'</pre><br />';
                }
                try{
                    $data[$key] = $service->{$configApplication['function']}($params[$key]);
                    if(APPLICATION_ENV == 'local'){
                        echo '<pre>',print_r($data[$key]),'</pre><br />';
                    }
                    if(!isset($data[$key]['status']) || (isset($data[$key]['status']) && $data[$key]['status'] != 1)){
                        $result = array(
                                        'error' => $data[$key]['status']
                                    );
                        $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params[$key],'result'=>$data[$key]),$gameId);
                        return $result;
                    }
                    if($this->checkCreatCache($dateEnd)){
                        $myMem->set($keyMem, serialize($data[$key]), false, $configGame->cache->time, $memcache);
                    }
                }catch(Exception $ex){
                    $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params[$key],'mess'=>$ex->getMessage()),$gameId);
                }
            }
        }
        $temp = array();
        for($dateStart;$dateStart<=$dateEnd;$dateStart = $helperTime->addDate($dateStart,1)){
            foreach($arrIndex as $key => $value){
                if(isset($data[$key]['status']) && $data[$key]['status'] == 1){
                    if(isset($data[$key]['result'][$dateStart]) && is_numeric($data[$key]['result'][$dateStart])){
                        $temp[$dateStart][$key]['status'] = 1;
                        $temp[$dateStart][$key]['result'] = $data[$key]['result'][$dateStart];
                    }else{
                        $temp[$dateStart][$key]['status'] = 1;
                        $temp[$dateStart][$key]['result'] = 0;
                    }
                }
            }
        }
        $data = $temp;
        $result = array(
                        'keyMem'    => $keyMem,
                        'data'      => $data,
                    );
        return $result;
    }
    # ccu
    public function ccu($conn, $service, $helperTime, $gameId, $arrTitle, $configApplication){
        $data = array();
        if(isset($arrTitle) && is_array($arrTitle)){
            $configApplication['serverList']        = implode(',',array_keys($arrTitle));
        }
        try{
            $params     = $conn->{$configApplication['prepareParams2']}($configApplication);
            if(APPLICATION_ENV == 'local'){
                echo '<pre>',print_r($params),'</pre><br />';
            }
            $data = $service->{$configApplication['function']}($params);
            if(APPLICATION_ENV == 'local'){
                echo '<pre>',print_r($data),'</pre><br />';
            }
            if(!isset($data['status']) || (isset($data['status']) && $data['status'] != 1)){
                $result = array(
                                'error' => $data['status']
                            );
                $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params,'result'=>$data),$gameId);
                return $result;
            }
            if(isset($data['status']) && $data['status'] == 1 && isset($data['result'][$params['argument3']])){
                $data['result'] = $data['result'][$params['argument3']];
            }
            if(isset($data['status']) && $data['status'] == 1 && is_array($data['result'])){
                foreach($arrTitle as $key2=>$title){
                    if(isset($data['result'][$key2])){
                        $data[$key2] = $data['result'][$key2];
                    }else{
                        $data[$key2] = 0;
                    }
                }
                unset($data['status']);
                unset($data['result']);
            }
        }catch(Exception $ex){
            $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params[$key],'mess'=>$ex->getMessage()),$gameId);
        }
        $result = array(
                        'data'      => $data,
                    );
        return $result;
    }
    # ccu Time
    public function ccuTime($conn, $service, $helperTime, $gameId, $arrTitle, $configApplication, $channels = null, $configGame = null){
        $data = array();
        if(isset($arrTitle) && is_array($arrTitle)){
            $configApplication['serverList']        = implode(',',array_keys($arrTitle));
        }
        try{
            $params     = $conn->{$configApplication['prepareParams']}($configApplication);
            if(APPLICATION_ENV == 'local'){
                echo '<pre>',print_r($params),'</pre><br />';
            }
            $data = $service->{$configApplication['function']}($params);
            if(APPLICATION_ENV == 'local'){
                echo '<pre>',print_r($data),'</pre><br />';
            }
            if(!isset($data['status']) || (isset($data['status']) && $data['status'] != 1)){
                $result = array(
                                'error' => $data['status']
                            );
                $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params,'result'=>$data),$gameId);
                return $result;
            }
            if(isset($data['status']) && $data['status'] == 1){
                foreach($data['result'] as $key=>$row){
                    $data['result'] = $row;
                }
            }
            if(isset($data['status']) && $data['status'] == 1 && is_array($data['result'])){
                foreach($arrTitle as $key2=>$title){
                    if(isset($data['result'][$key2])){
                        $data[$key2] = $data['result'][$key2];
                    }else{
                        $data[$key2] = 0;
                    }
                }
                $disable = array();
                if(isset($configGame->ccu->channel->disable)){
                    $disable = $configGame->ccu->channel->disable->toArray();
                }
                if(isset($data['result']['totalServers']) && !in_array('TOTAL',$disable)){
                    $data['totalServers'] = $data['result']['totalServers'];
                }
                if(isset($channels) && is_array($channels) && $channels){
                    foreach($channels as $row){
                        if(isset($data['result']['totalServers'.$row]) && ((!isset($disable)) || (isset($disable) && !in_array($row,$disable)))){
                            $data['totalServers'.$row] = $data['result']['totalServers'.$row];
                        }
                    }
                }
                unset($data['status']);
                unset($data['result']);
            }
        }catch(Exception $ex){
            $this->writeLog(array('wsdl'=>$configApplication['wsdl'],'params'=>$params,'mess'=>$ex->getMessage()),$gameId);
        }
        $result = array(
                        'data'      => $data,
                    );
        return $result;
    }
    // chưa sử dụng. Đang dùng revenueindex
    public function pcuindex($conn, $service, $memcache, $myMem, $helperTime, $gameId, $urlModule, $urlController, $urlAction, $dateStart, $dateEnd, $arrIndex, $configGame, $configApplication){
    
    }
    // chưa sử dụng. Đang dùng revenueindex
    public function acuindex($conn, $service, $memcache, $myMem, $helperTime, $gameId, $urlModule, $urlController, $urlAction, $dateStart, $dateEnd, $arrIndex, $configGame, $configApplication){
        
    }
    public function checkCreatCache($date){
        $time = date("Y-m-d",strtotime(date("Y-m-d")) - 86400);#ngày lấy data là ngày hôm trước
        if($date == $time){
            if(date("His") > 82959){
                return true;
            }else{
                return false;
            }
        }
        return true;
    }
//    public function checkCreatCache($date){
//        $time = date("Y-m-d");#ngày lấy data là ngày hôm nay
//        if($date == $time){
//            if(date("His") > 85959){
//                return true;
//            }else{
//                return false;
//            }
//        }
//        return true;
//    }
    public function timeRequest($params, $helperTime){
        
        $dateStart  = $helperTime->addDate(date("Y-m-d"),-30);
        $dateEnd    = date("Y-m-d");
        if(isset($params['dateStart']) && isset($params['dateEnd'])){
            $dateStart  = $params['dateStart'];
            $dateEnd    = $params['dateEnd'];
            if($dateStart > date('Y-m-d')){
                $dateStart  = $helperTime->addDate(date("Y-m-d"),-30);
                $dateEnd    = date("Y-m-d");
            }elseif($dateStart == date('Y-m-d')){
                $dateStart = date("Y-m-d");
            }elseif($dateStart < date('Y-m-d') && $dateEnd >= date('Y-m-d')){
                $dateEnd    = $helperTime->addDate(date("Y-m-d"),-1);
            }elseif($dateStart > $dateEnd){
                $temp = $dateStart;
                $dateStart = $dateEnd;
                $dateEnd = $temp;
                unset($temp);
            }
            $subDay = $helperTime->subDatetime($dateEnd, $dateStart);
            $result = array(
                            'prevDateStart'     => $helperTime->addDate($dateStart,-$subDay),
                            'nextDateEnd'       => $helperTime->addDate($dateEnd,$subDay),
                            'dateStart'         => $dateStart,
                            'dateEnd'           => $dateEnd
                        );
            return $result;
        }else{
            $date = $helperTime->addDate(date("Y-m-d"),-1);
            if(isset($params['date']))
                $date = $params['date'];
            
            $month  = date('m', strtotime($date));
            $year   = date('Y', strtotime($date));
            $dateStart  = "$year-$month-01";
            if(date("Y-m") == "$year-$month"){
                $dateEnd    = "$year-$month-".date("d");
            }elseif(date("Y-m") > "$year-$month"){
                $dayOfMonth = $helperTime->numberDayOfMonth($date);
                $dateEnd    = "$year-$month-$dayOfMonth";
            }
            if($dateEnd == date("Y-m-d"))
                $dateEnd = $helperTime->addDate($dateEnd,-1);
            $result = array(
                            'date'              => $date,
                            'prevDate'          => date("Y-m-d",mktime(0, 0, 0, $month-1, 01, $year)),
                            'nextDate'          => date("Y-m-d",mktime(0, 0, 0, $month+1, 01, $year)),
                            'dateStart'         => $dateStart,
                            'dateEnd'           => $dateEnd
                        );
            return $result;
        }
        
    }
    public function writeLog($data, $gameId = NULL){
        $path = PUBLIC_PATH.'/logs/';
        $filename = date('Y_m_d');
        if($gameId){
            $filename .= '_'.$gameId;
            $this->emailReport($data,$gameId);
        }
        $handle = fopen($path . $filename . '.txt', 'a');
        
        $text = date('Y-m-d H:i:s');
        if(isset($data['result']) && is_array($data['result'])){
            $text .= ' ### result: '.json_encode($data['result']);
        }
        if(isset($data['wsdl']) && $data['wsdl']){
            $text .= ' ### wsdl: '.$data['wsdl'];
        }
        if(isset($data['params']) && is_array($data['params'])){
            $text .= ' ### params: '.json_encode($data['params']);
        }
        if(isset($data['mess']) && $data['mess']){
            $text .= ' ### service error: ' . $data['mess'];
        }
        $text .= "\n";
        
        fwrite($handle, $text);
        fclose($handle);
    }
    public function emailReport($data,$gameId){
        if(!file_exists(CONFIG_PATH.'/email.ini')){
            #echo "Thieu config gui mail <br />\r\n";
            return;
        }
        $configEmail = new Zend_Config_Ini(CONFIG_PATH.'/email.ini',APPLICATION_ENV);
        if(!isset($configEmail->email->reportError->status) || (isset($configEmail->email->reportError->status) && $configEmail->email->reportError->status != 1)){
            #echo "Chuc nang gui mail dang tam khoa <br />\r\n";
            return;
        }
        if(!isset($configEmail->email->reportError) || (isset($configEmail->email->reportError) && is_array($configEmail->email->reportError) && $configEmail->email->reportError)){
            #echo "Khong co cau hinh nguoi nhan email <br />\r\n";
            return;
        }
        
        $mail = new Zend_Mail('UTF-8');
        $mail->setFrom('kpi@ssgroup.com.vn', 'KPI Report');
        $value = $configEmail->email->reportError->value;
        $cc = $configEmail->email->reportError->cc->toArray();
        foreach($value as $row){
            $mail->addTo($row);
        }
        foreach($cc as $row){
            $mail->addCc($row);
        }
        $mail->setSubject('[KPI Report] Service error: '.date('Y-m-d'));
        $content = 'Hệ thống service cho KPI Report hiện đang gặp lỗi. Vui lòng kiểm tra log để biết thêm chi tiết: <br />';
        if(is_array($data)){
            if(isset($gameId) && $gameId){
                $content .= 'Game: '.$gameId."<br />";
            }
            if(isset($data['wsdl']) && $data['wsdl']){
                $content .= 'WSDL: '.$data['wsdl']."<br />";
            }
            if(isset($data['params']) && $data['params']){
                $content .= 'Params: <pre>'.var_export($data['params'], true)."</pre><br />";
            }
            if(isset($data['mess']) && $data['mess']){
                $content .= 'Service error: ' . $data['mess'];
            }
        }
        
        $mail->setBodyHtml($content);
        try{
            $mail->send();
            # sau khi gui mail thi update lai trang thai khong cho gui mail nua (tranh spam)
            $configEmail = new Zend_Config_Ini(CONFIG_PATH.'/email.ini',null,  array('skipExtends' => true, 'allowModifications' => true));
            $configEmail->production->email->reportError->status = 0;
            $writer = new Zend_Config_Writer_Ini(array('config'   => $configEmail, 'filename' => CONFIG_PATH.'/email.ini'));
            $writer->write();
        }catch(Zend_Mail_Exception $ex){
            
        }
    }
}